package com.store.framework.rest;

import java.util.List;
import java.util.UUID;

import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.store.framework.entry.RootMap;
import com.store.framework.logic.IAppRootMapLogic;
import com.store.framework.logic.imp.AppRootMapLogic;

public class ARootMapService {

	IAppRootMapLogic rootmap = new AppRootMapLogic();
	private static Log LOG = LogFactory.getLog(ARootMapService.class);

	@POST
	@Path("AddRootMap")
	@Produces("application/json; charset=UTF-8")
	public String AddRootMap(RootMap input) {
	LOG.info(input);
		JSONObject jo = JSONObject.fromObject(input);
		@SuppressWarnings("static-access")
		RootMap am = (RootMap) jo.toBean(jo, RootMap.class);
		am.setId(UUID.randomUUID().toString());
		rootmap.Add(am);

		return "{\"result\":1}";
	}

	@POST
	@Path("selectRootMap")
	@Produces("application/json; charset=UTF-8")
	public String selectRootMap() {
		@SuppressWarnings("rawtypes")
		List list = rootmap.select();
		JSONArray jo = JSONArray.fromObject(list);
		System.out.println(jo);
		return jo.toString();
	
	}

	public static void main(String[] args) {
		new ARootMapService().selectRootMap();
	}

}
